package hku.cs.lunuo.page;

import hku.cs.lunuo.LunuoPlugin;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class PrimaryPrefPage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {

	public PrimaryPrefPage() {
		super(GRID);
		setDescription("General Lunuo Setting");
		setPreferenceStore(LunuoPlugin.getDefault().getPreferenceStore());
	}

	@Override
	public void init(IWorkbench workbench) {
			
	}

	@Override
	protected void createFieldEditors() {
		Composite parent = getFieldEditorParent();
		
		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayoutData(gridData);
		
		
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		composite.setLayout(layout);
		
		
		Label l = new Label(composite, SWT.WRAP | SWT.HORIZONTAL);	
		l.setText("Max Project value is let Lunuo know how many Project can" +
				" be contained in repository. Max History means the max number" +
				" historys of one project.");
		gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		l.setLayoutData(gridData);
		
		
		Group g = new Group(composite, SWT.NONE);
		g.setText("Repository Setting");
		gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		g.setLayoutData(gridData);
		
		IntegerFieldEditor maxProject = new IntegerFieldEditor(
				PreferenceConstant.MAXPRO_KEY,
				"max project",
				g,
				PreferenceConstant.MAXPRO_VALUE);
		
		IntegerFieldEditor maxProjectRun = new IntegerFieldEditor(
				PreferenceConstant.MAXPRO_RUN_KEY,
				"max History",
				g,
				PreferenceConstant.MAXPRO_RUN_VALUE);
		addField(maxProject);
		addField(maxProjectRun);
		
		l = new Label(composite, SWT.WRAP | SWT.HORIZONTAL);	
		l.setText("\nDo smart testcase instrument when run Test.This will contribute error" +
				"if plugin find the testcase has been instrument but actually not. The" +
				"error happened especially when you modify lunuo repositry manually!");
		gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		l.setLayoutData(gridData);
		
		BooleanFieldEditor isSmart = new BooleanFieldEditor(
				PreferenceConstant.SMARTTESTINSTRU_KEY,
				"smart instrument",
				composite);
		
		addField(isSmart);
		
	}

}
